package com.kangyi.admin.controller;

import com.kangyi.admin.service.NursingHomeServiced;
import com.kangyi.dto.*;
import com.kangyi.result.Result;
import com.kangyi.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/admin/nursing")
@Slf4j
@Api(tags = "养老院-养老院相关接口")
public class NursingHomeController {

    @Autowired
    private NursingHomeServiced nursingHomeServiced;

    @GetMapping("/inquiryOverview/{id}")
    @ApiOperation("查询养老院概况")
//    @Cacheable(cacheNames = "NursingHome_", key = "'adminOverView_'+#id")
    public Result<NursingHomeOverviewVO> overviewNursingHome(@PathVariable Integer id){
        log.info("查询养老院概况：{}",id);
        try {
            NursingHomeOverviewVO nursingHomeOverviewVO = nursingHomeServiced.getOverview(id);
            return Result.success(nursingHomeOverviewVO,"查询成功");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PutMapping("/updateOverview")
    @ApiOperation("修改养老院概况")
    @CacheEvict(cacheNames = "NursingHome_", allEntries = true)
    public Result updateOverview(@RequestBody NursingHomeOverviewDTO nursingHomeOverviewDTO){
        log.info("修改养老院概况:{}",nursingHomeOverviewDTO);
        try {
            nursingHomeServiced.updateOverview(nursingHomeOverviewDTO);
            return Result.success("修改成功!");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/inquiryBasicInformation/{id}")
    @ApiOperation("查询基本信息")
//    @Cacheable(cacheNames = "NursingHome_", key = "'adminBasic_'+#id")
    public Result<NursingHomeBasicInformationVO> inquiryBasicInformation(@PathVariable Integer id){
        log.info("查询基本信息:{}",id);
        try {
            NursingHomeBasicInformationVO nursingHomeBasicInformationVO = nursingHomeServiced.inquiryBasicInformation(id);
            return Result.success(nursingHomeBasicInformationVO,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PutMapping("/updateBasicInformation")
    @ApiOperation("修改基本信息")
    @CacheEvict(cacheNames = "NursingHome_", allEntries = true)
    public Result updateBasicInformation(@RequestBody NursingHomeBasicInformationDTO nursingHomeBasicInformationDTO){
        log.info("修改基本信息：{}",nursingHomeBasicInformationDTO);
        try {
            nursingHomeServiced.updateBasicInformation(nursingHomeBasicInformationDTO);
            return Result.success("修改成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/inquiryRequirement/{id}")
    @ApiOperation("查询入住条件")
//    @Cacheable(cacheNames = "NursingHome_", key = "'adminRequirement'+#id")
    public Result<List<NursingHomeRequirementVO>> inquiryRequirement(@PathVariable Integer id){
        log.info("查询入住条件:{}",id);
        try {
            List<NursingHomeRequirementVO> nursingHomeRequirementVOList = nursingHomeServiced.inquiryRequirement(id);
            return Result.success(nursingHomeRequirementVOList,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PutMapping("/updateRequirement")
    @ApiOperation("修改入住条件")
    @CacheEvict(cacheNames = "NursingHome_", allEntries = true)
    public Result updateRequirement(@RequestBody NursingHomeRequirementDTO nursingHomeRequirementDTO){
        log.info("修改入住条件：{}",nursingHomeRequirementDTO);
        try {
            nursingHomeServiced.updateRequirement(nursingHomeRequirementDTO);
            return Result.success("修改成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }


    @GetMapping("/inquiryService/{id}")
    @ApiOperation("查询特色服务")
//    @Cacheable(cacheNames = "NursingHome_", key = "'adminService_'+#id")
    public Result<List<NursingHomeServiceVO>> inquiryService(@PathVariable Integer id){
        log.info("查询特色服务：{}",id);
        try {
            List<NursingHomeServiceVO> nursingHomeServiceVOList = nursingHomeServiced.inquiryService(id);
            return Result.success(nursingHomeServiceVOList,"查询成功");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PutMapping("/updateService")
    @ApiOperation("修改特色服务")
    @CacheEvict(cacheNames = "NursingHome_", allEntries = true)
    public Result updateService(@RequestBody NursingHomeServiceDetailDTO nursingHomeServiceDetailDTO){
        log.info("修改特色服务：{}",nursingHomeServiceDetailDTO);
        try {
            nursingHomeServiced.updateService(nursingHomeServiceDetailDTO);
            return Result.success("修改成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
